﻿using System;
using System.Windows.Forms;
using Presenter;

namespace VectorsWinForm
{
    public partial class VectorsOperationsWinForm : Form, IView
    {
        public VectorsOperationsWinForm()
        {
            InitializeComponent();
            var presenter = new Presenter.Presenter(this, new Logger.Logger("Log.txt"));
            Attach(presenter);
        }

        public void Attach(IPresenterCallbacks callback)
        {
            buttonAdd.Click += (sender, e) => callback.Add();
            buttonSub.Click += (sender, e) => callback.Sub();
            buttonDot.Click += (sender, e) => callback.ScalarProduct();
            buttonNorm.Click += (sender, e) => callback.Norm();
            buttonNormalize.Click += (sender, e) => callback.Normalize();
            buttonCross.Click += (sender, e) => callback.CrossProduct();
            buttonViewLog.Click += (sender, e) => callback.LoadLog();
        }

        public void SetFirstVector(String x, String y, String z)
        {
            vector1X.Text = x;
            vector1Y.Text = y;
            vector1Z.Text = z;
        }

        public void SetSecondVector(String x, String y, String z)
        {
            vector2X.Text = x;
            vector2Y.Text = y;
            vector2Z.Text = z; 
        }

        public String[] GetFirstVector()
        {
            var fv=new String[3];
            fv[0] = vector1X.Text;
            fv[1] = vector1Y.Text;
            fv[2] = vector1Z.Text;
            return fv;
        }

        public String[] GetSecondVector()
        {
            var sv = new String[3];
            sv[0] = vector2X.Text;
            sv[1] = vector2Y.Text;
            sv[2] = vector2Z.Text;
            return sv;
        }

        public void ShowError(string error)
        {
            labelError.Text = error;
        }

        public void HideResults()
        {
            labelError.Text = "";
            resX.Text = "";
            resY.Text = "";
            resZ.Text = "";
            scRes.Text = "";
        }

        public void SetVectorResult(string[] strVector)
        {
            resX.Text = strVector[0];
            resY.Text = strVector[1];
            resZ.Text = strVector[2];
        }

        public void SetScalarResult(string result)
        {
            scRes.Text = result;
        }

        public void AddLogRecord(string record)
        {
             log.Text += string.Format("{0}\n", record);
        }
    }
}
